|
1
|
|
|
var newUserDates = []; |
|
2
|
|
|
var newUserTypes = []; |
|
3
|
|
|
|
|
4
|
|
|
var maxVotes = 0; |
|
5
|
|
|
var valuesChanged = false; |
|
6
|
|
|
|
|
7
|
|
|
var tzOffset = new Date().getTimezoneOffset(); |
|
8
|
|
|
|
|
9
|
|
|
$.fn.switchClass = function(a, b) { |
|
10
|
|
|
this.removeClass(a); |
|
11
|
|
|
this.addClass(b); |
|
12
|
|
|
return this; |
|
13
|
|
|
}; |
|
14
|
|
|
|
|
15
|
|
|
function updateCommentsCount(){ |
|
16
|
|
|
//todo Update the Badgecounter |
|
17
|
|
|
$('#comment-counter').removeClass('no-comments'); |
|
18
|
|
|
$('#comment-counter').text(parseInt($('#comment-counter').text()) +1); |
|
19
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function updateBest(){ |
|
23
|
|
|
maxVotes = 0; |
|
24
|
|
|
$('.counter').each(function() { |
|
25
|
|
|
var yes = parseInt($(this).find('.yes').text()); |
|
26
|
|
|
var no = parseInt($(this).find('.no').text()); |
|
27
|
|
|
if(yes - no > maxVotes) { |
|
28
|
|
|
maxVotes = yes - no; |
|
29
|
|
|
} |
|
30
|
|
|
}); |
|
31
|
|
|
var i = 0; |
|
|
|
|
|
|
32
|
|
|
$('.vote').each(function() { |
|
33
|
|
|
var yes = parseInt($(this).find('.yes').text()); |
|
34
|
|
|
var no = parseInt($(this).find('.no').text()); |
|
35
|
|
|
$(this).toggleClass('winner', yes - no === maxVotes); |
|
36
|
|
|
}); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function updateCounters(){ |
|
40
|
|
|
$('.result-cell.yes').each(function() { |
|
41
|
|
|
$(this).text($('#voteid_'+ $(this).attr('data-voteId') + '.poll-cell.yes').length); |
|
42
|
|
|
}); |
|
43
|
|
|
$('.result-cell.no').each(function() { |
|
44
|
|
|
$(this).text($('#voteid_'+ $(this).attr('data-voteId') + '.poll-cell.no').length); |
|
45
|
|
|
}); |
|
46
|
|
|
updateBest(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function switchSidebar() { |
|
50
|
|
|
if ($('#app-content').hasClass('with-app-sidebar')) { |
|
51
|
|
|
OC.Apps.hideAppSidebar(); |
|
52
|
|
|
} else { |
|
53
|
|
|
OC.Apps.showAppSidebar(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$(document).ready(function () { |
|
59
|
|
|
// count how many times in each date |
|
60
|
|
|
new Clipboard('.copy-link'); |
|
|
|
|
|
|
61
|
|
|
updateBest(); |
|
62
|
|
|
$('.delete-poll').click(function(){ |
|
63
|
|
|
deletePoll(this); |
|
|
|
|
|
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
$('#switchDetails').click(function(){ |
|
67
|
|
|
switchSidebar(); |
|
68
|
|
|
}); |
|
69
|
|
|
|
|
70
|
|
|
$('#closeDetails').click(function(){ |
|
71
|
|
|
OC.Apps.hideAppSidebar(); |
|
72
|
|
|
}); |
|
73
|
|
|
|
|
74
|
|
|
$('.poll.avatardiv').each(function(i, obj) { |
|
75
|
|
|
$(obj).avatar(obj.title, 32); |
|
76
|
|
|
}); |
|
77
|
|
|
|
|
78
|
|
|
$('.vote.time').each(function() { |
|
79
|
|
|
var extendedDate = new Date($(this).attr("data-value-utc").replace(/ /g,"T")+"Z"); //Fix display in Safari and IE |
|
80
|
|
|
|
|
81
|
|
|
$(this).find('.month').text(extendedDate.toLocaleString(window.navigator.language, {month: 'short'})); |
|
82
|
|
|
$(this).find('.day').text(extendedDate.toLocaleString(window.navigator.language, {day: 'numeric'})); |
|
83
|
|
|
$(this).find('.dayow').text(extendedDate.toLocaleString(window.navigator.language, {weekday: 'short'})); |
|
84
|
|
|
$(this).find('.time').text(extendedDate.toLocaleTimeString(window.navigator.language, {hour: 'numeric', minute:'2-digit', timeZoneName:'short'})); |
|
85
|
|
|
|
|
86
|
|
|
}); |
|
87
|
|
|
|
|
88
|
|
|
$('#submit_finish_vote').click(function() { |
|
89
|
|
|
var form = document.finish_vote; |
|
90
|
|
|
var ac = document.getElementById('user_name'); |
|
91
|
|
|
if (ac !== null) { |
|
92
|
|
|
if(ac.value.length >= 3){ |
|
93
|
|
|
form.elements.userId.value = ac.value; |
|
94
|
|
|
} else { |
|
95
|
|
|
alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); |
|
96
|
|
|
return; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
var check_notif = document.getElementById('check_notif'); |
|
100
|
|
|
var newUserDates = [], newUserTypes = []; |
|
101
|
|
|
$(".poll-cell.active").each(function() { |
|
102
|
|
|
if($(this).hasClass('no')) { |
|
103
|
|
|
newUserTypes.push(0); |
|
104
|
|
|
} else if ($(this).hasClass('yes')){ |
|
105
|
|
|
newUserTypes.push(1); |
|
106
|
|
|
} else if($(this).hasClass('maybe')){ |
|
107
|
|
|
newUserTypes.push(2); |
|
108
|
|
|
} else { |
|
109
|
|
|
newUserTypes.push(-1); |
|
110
|
|
|
} |
|
111
|
|
|
if (isNaN($(this).attr('data-value'))) { |
|
112
|
|
|
newUserDates.push($(this).attr('data-value')); |
|
113
|
|
|
} else { |
|
114
|
|
|
newUserDates.push(parseInt($(this).attr('data-value'))); |
|
115
|
|
|
} |
|
116
|
|
|
}); |
|
117
|
|
|
form.elements.dates.value = JSON.stringify(newUserDates); |
|
118
|
|
|
form.elements.types.value = JSON.stringify(newUserTypes); |
|
119
|
|
|
form.elements.receiveNotifications.value = (check_notif && check_notif.checked) ? 'true' : 'false'; |
|
120
|
|
|
form.elements.changed.value = valuesChanged ? 'true' : 'false'; |
|
121
|
|
|
form.submit(); |
|
122
|
|
|
}); |
|
123
|
|
|
|
|
124
|
|
|
$('#submit_send_comment').click(function(e) { |
|
125
|
|
|
e.preventDefault(); |
|
126
|
|
|
var form = document.send_comment; |
|
127
|
|
|
var ac = document.getElementById('user_name_comm'); |
|
128
|
|
|
if (ac !== null) { |
|
129
|
|
|
if(ac.value.length >= 3){ |
|
130
|
|
|
form.elements.userId.value = ac.value; |
|
131
|
|
|
} else { |
|
132
|
|
|
alert(t('polls', 'You are not registered.\nPlease enter your name to vote\n(at least 3 characters).')); |
|
133
|
|
|
return; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
var comment = document.getElementById('commentBox'); |
|
137
|
|
|
if(comment.value.trim().length <= 0) { |
|
138
|
|
|
alert(t('polls', 'Please add some text to your comment before submitting it.')); |
|
139
|
|
|
return; |
|
140
|
|
|
} |
|
141
|
|
|
var data = { |
|
142
|
|
|
pollId: form.elements.pollId.value, |
|
143
|
|
|
userId: form.elements.userId.value, |
|
144
|
|
|
commentBox: comment.value.trim() |
|
145
|
|
|
}; |
|
146
|
|
|
$('.new-comment .icon-loading-small').show(); |
|
147
|
|
|
$.post(form.action, data, function(data) { |
|
148
|
|
|
$('.comments .comment:first').after('<div class="comment"><div class="comment-header"><span class="comment-date">' + data.date + '</span>' + data.userName + '</div><div class="wordwrap comment-content">' + data.comment + '</div></div>'); |
|
149
|
|
|
$('.new-comment textarea').val('').focus(); |
|
150
|
|
|
$('.new-comment .icon-loading-small').hide(); |
|
151
|
|
|
updateCommentsCount(); |
|
152
|
|
|
}).error(function() { |
|
153
|
|
|
alert(t('polls', 'An error occurred, your comment was not posted.')); |
|
154
|
|
|
$('.new-comment .icon-loading-small').hide(); |
|
155
|
|
|
}); |
|
156
|
|
|
}); |
|
157
|
|
|
|
|
158
|
|
|
$(".share input").click(function() { |
|
159
|
|
|
$(this).select(); |
|
160
|
|
|
}); |
|
161
|
|
|
|
|
162
|
|
|
$('.toggle-cell').tooltip(); |
|
163
|
|
|
$('.time-slot').tooltip(); |
|
164
|
|
|
$('.avatardiv').tooltip(); |
|
165
|
|
|
updateCounters(); |
|
166
|
|
|
|
|
167
|
|
|
}); |
|
168
|
|
|
|
|
169
|
|
|
$(document).on('click', '.toggle-cell, .poll-cell.active', function() { |
|
170
|
|
|
valuesChanged = true; |
|
171
|
|
|
var $nextClass = ""; |
|
172
|
|
|
var $toggleAllClasses = ""; |
|
173
|
|
|
|
|
174
|
|
|
if($(this).hasClass('yes')) { |
|
175
|
|
|
$nextClass = "no"; |
|
176
|
|
|
$toggleAllClasses= "yes"; |
|
177
|
|
|
} else if($(this).hasClass('no')) { |
|
178
|
|
|
$nextClass = "maybe"; |
|
179
|
|
|
$toggleAllClasses= "no"; |
|
180
|
|
|
} else if($(this).hasClass('maybe')) { |
|
181
|
|
|
$nextClass = "yes"; |
|
182
|
|
|
$toggleAllClasses= "maybe"; |
|
183
|
|
|
} else { |
|
184
|
|
|
$nextClass = "yes"; |
|
185
|
|
|
$toggleAllClasses= "maybe"; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
$(this).removeClass('yes no maybe unvoted'); |
|
189
|
|
|
$(this).addClass($nextClass); |
|
190
|
|
|
|
|
191
|
|
|
if($(this).hasClass('toggle-cell')) { |
|
192
|
|
|
$(".poll-cell.active").removeClass('yes no maybe unvoted'); |
|
193
|
|
|
$(".poll-cell.active").addClass($toggleAllClasses); |
|
194
|
|
|
} |
|
195
|
|
|
updateCounters(); |
|
196
|
|
|
}); |
|
197
|
|
|
|
|
198
|
|
|
|